﻿//---------------------------------------------------------------------------------
// Copyright 2011 Microsoft Corporation
// Licensed under the Microsoft Public License (MS-PL) (the "License"); 
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.opensource.org/licenses/ms-pl.html
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR 
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, 
// INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 
// CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
// MERCHANTABLITY OR NON-INFRINGEMENT. 
// See the Microsoft Public License (MS-PL) for the specific language governing 
// permissions and limitations under the License.
//---------------------------------------------------------------------------------
using System;
using System.Text;

namespace Microsoft.Telco.WindowsLive
{
	public class Offer
	{

		private static string[] OfferNames = new string[] { "Messenger", "WL_Activities", "WL_Calendar", "WL_Client", "WL_Contacts", "WL_Photos", "WL_Documents", "WL_Profiles", "WL_SyncFolders", "WL_Test", "WL_WindowsClient", "WL" };

		// Methods
		public Offer()
		{
		}

		internal Offer(string offerString)
		{
			this.ParseOfferString(offerString);
		}

		private void ParseOfferString(string offerString)
		{
			long num2;
			if (string.IsNullOrEmpty(offerString))
			{
				throw new ArgumentNullException("offerString");
			}
			string[] strArray = offerString.Split(new char[] { AuthConstants.Wrap.OfferSeparator[1], AuthConstants.Wrap.OfferSeparator[2] });
			if (strArray.Length < 2)
			{
				throw new ArgumentException("Invalid offer string.");
			}
			string str = strArray[0];
			if (string.IsNullOrEmpty(str))
			{
				throw new ArgumentException("Invalid offer string.");
			}
			foreach (string str2 in OfferNames)
			{
				int index = str.IndexOf(str2);
				if (index != -1)
				{
					this.Namespace = str.Substring(0, index);
					this.Name = str2;
					break;
				}
			}
			this.Action = strArray[1];
			if ((strArray.Length == 3) && long.TryParse(strArray[2], out num2))
			{
				this.Expiration = AuthConstants.Wrap.BaseDateTime.AddSeconds((double)num2);
			}
		}

		public override string ToString()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append(this.Namespace).Append(this.Name).Append(AuthConstants.Wrap.OfferSeparator[1]).Append(this.Action);
			return builder.ToString();
		}

		// Properties
		public string Action { get; set; }
		public DateTime Expiration { get; set; }
		public string Name { get; set; }
		public string Namespace { get; set; }

	}


}
